/**
 * Created by Administrator on 2020/11/24.
 */
layui.use(['table','form','layer','layedit', 'laydate'], function(){
    var table = layui.table
        ,form = layui.form
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate
        ,$=layui.$;

    //监听提交
    form.on('submit(demo1)', function(data){
        table.reload('test',{
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where:data.field
        });
        return false;
    });

    table.render({
        elem: '#test'
        ,url:config.gatewayUri+'/'+config.deviceServiceId+'/api/device-fault-record/admin/getDeviceFaultRecordList'
        ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
        ,cols: [[
            {field:'devicenumber', title: '设备编号', sort: true}
            ,{field:'devicename', title: '设备名称'}
            ,{field:'venuesname', title: '场地名称'}
            ,{field:'deviceaddress', title: '设备地址'}
            ,{field:'faultinfo', title: '故障内容'}
            ,{field:'ctime',  title: '故障时间'}
        ]]
        ,page:true
        ,limits : [5,10]
        ,limit:2
        ,response:{
            statusCode:'200'
        }
        ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": res.data.list //解析数据列表
            };
        }
    });
    table.on('toolbar(newsList)', function(obj){

        switch(obj.event){
            case 'exportExcel':
                location.href=config.gatewayUri+"/"+config.deviceServiceId+"/api/device-fault-record/exportExcel";
                break;
            //自定义头工具栏右侧图标 - 提示
            //case 'LAYTABLE_TIPS':
            //    layer.alert('这是工具栏右侧自定义的一个图标按钮');
            //    break;
        }
    });
});